#
#
#
#

require 'test/unit'
require 'bytes' 

def b_s(what)
  "Testing Bytes::string(#{what.to_s}) : " + Bytes::string(what).bytes.to_a.to_s + "."
end

class BytesTest < Test::Unit::TestCase
  
  def test_bytes_string
    assert(Bytes.string(nil) == "", b_s(nil))
    assert(Bytes.string(1)   == "\1", b_s(1))
    assert(Bytes.string(0x10)   == "\x10", b_s(0x10))
    assert(Bytes.string(0x1234) == "\x34\x12", b_s(0x1234))
    assert(Bytes.string(0x12345678) == "\x78\x56\x34\x12", b_s(0x12345678))
    assert(Bytes.string(0x1234567890ABCDE0) == "\xe0\xcd\xab\x90\x78\x56\x34\x12", b_s(0x1234567890ABCDE))
    assert(Bytes.string(0.23) == "q=\n\xD7\xA3p\xCD?", b_s(0.23))
  end
  
  def test_bytes_byte
    assert(Bytes.byte(nil) == nil)
    assert(Bytes.byte(0x0f) == "\x0f")
  end
  
  def test_bytes_word
    assert(Bytes.word(nil) == nil) 
    assert(Bytes.word(0x1234) == "\x34\x12")
  end
  
  def test_bytes_dword
    assert(Bytes.dword(nil) == nil) 
    assert(Bytes.dword(0x12345678) == "\x78\x56\x34\x12")  
  end
  
  def test_bytes_pack
    assert_raise(RangeError) { Bytes.pack("abcdefghijklmnopqrstuvwxyz", 20) }
  end
    
end
